package com.dwxt.community.dao;

import com.dwxt.community.entity.IntegralRecord;
import com.dwxt.community.entity.IntegralRecordExample;
import com.dwxt.community.entity.OfflineActivity;
import com.dwxt.community.entity.vo.IntegralRankVo;
import com.dwxt.community.entity.vo.IntegralRecordListVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface IntegralRecordMapper {
    long countByExample(IntegralRecordExample example);

    int deleteByExample(IntegralRecordExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(IntegralRecord record);

    int insertSelective(IntegralRecord record);

    List<IntegralRecord> selectByExample(IntegralRecordExample example);

    IntegralRecord selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") IntegralRecord record, @Param("example") IntegralRecordExample example);

    int updateByExample(@Param("record") IntegralRecord record, @Param("example") IntegralRecordExample example);

    int updateByPrimaryKeySelective(IntegralRecord record);

    int updateByPrimaryKey(IntegralRecord record);

    Map<String, Integer> selectMonthIntegral(@Param("userId") String userId, @Param("year") Integer year,
                                             @Param("month") Integer month);

    Integer selectIntegralRank(String currentUserId);

    @Select("SELECT u.username userName, t.trash_type type,tc.control_no equid,t.got_integral integral,u.community_name communityName,u.house_number houseNumber FROM trash_integral_recoad t LEFT JOIN `user` u ON t.deliverer_id=u.id LEFT JOIN trash_can tc ON t.device_id = tc.device_id  ORDER BY t.create_time DESC LIMIT 6 ;")
    List<IntegralRecordListVo> selectTopList();

    //当月积分排行榜
    List<IntegralRankVo> selectTotalMonthIntegral();

    //当年积分排行榜
    List<IntegralRankVo> selectTotalYearIntegral();

    //总积分排行
    List<IntegralRankVo> selectTotalIntegral();

    @Select("select ifnull(sum(integral),0) from integral_record where  user_id= #{id} and category='垃圾分类' ;")
    Integer sum(String id);

    List<OfflineActivity> selectLineActivityRecord();

    Integer sumByCategory(String category);

    Integer sumByUserId(String userId);

    Integer sumPlusIntegral();

    Integer sumNegativeIntegral();

    List<Map> selectIntegralStatisticsByActive();

    List<Map> selectIntegralStatisticsByTime(@Param("year") Integer year, @Param("month") Integer month);

    List<Map> selectIntegralStatisticsByUser(@Param("phone") String phone,@Param("type") Integer type,
                                             @Param("sequence") String sequence);

    List<Map> selectTotalIntegralStatistics();

    List<Map> selectPlusAndNegativeIntegral(String date);

}